package fr.paris8.iut.info.iddl;

/*
 * By PHAM Tuan Anh *
 */


import fr.paris8.iut.info.iddl.IDDLReasonerFactory;
import java.net.InetAddress;
import java.net.URL;
import org.semanticweb.owlapi.owllink.OWLlinkReasonerConfiguration;
import org.semanticweb.owlapi.owllink.server.AbstractOWLlinkReasonerConfiguration;
import org.semanticweb.owlapi.owllink.server.OWLlinkHTTPXMLServer;
import org.semanticweb.owlapi.owllink.server.OWLlinkServer;

import org.semanticweb.owlapi.reasoner.OWLReasonerFactory;


public class IDDLServer implements OWLlinkServer{
     
   
    private  OWLlinkReasonerConfiguration reasonerConfiguration = null;
    private  OWLlinkServer server = null;   
    
    private  OWLReasonerFactory reasonerFactory;
    //private static OWLlinkReasoner reasoner;
    private int port=8080;
   

    public IDDLServer(int port){
       this.port = port;
    }

    // Fonction pour démarrer le serveur
    public void run() {
        try
        {
            InetAddress thisIp =InetAddress.getLocalHost();
            reasonerConfiguration = new OWLlinkReasonerConfiguration(new URL("http://"+thisIp.getHostAddress()+":"+port)); // Configure la configuration de raisonneur
            reasonerFactory = new IDDLReasonerFactory();
            AbstractOWLlinkReasonerConfiguration serverConfiguration = new AbstractOWLlinkReasonerConfiguration(reasonerConfiguration);
            server = new OWLlinkHTTPXMLServer(reasonerFactory, serverConfiguration,port);
            
            server.run();
        }catch(Exception e)
        {
            
        }
    }

   // Fonction pour arrêter le serveur
    public void stop() throws InterruptedException {
        if(server!=null) {
            try {
                server.stop();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }


}
	

